<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<link rel="shortcut icon" href="/favicon.ico"/>
	<title>后台管理</title>
	<%
	include("/common/static.html"){}
	%>
	<script type="text/javascript" src="/admin/js/common.js" ></script>
	<link rel="stylesheet" href="/admin/common/css/common.css" />
	<link rel="stylesheet" href="/admin/css/common.css" />
	<link rel="stylesheet" href="/admin/css/apply.css" />
</head>
<body>
<%
include("/admin/common/menu.html"){}
%>
<div class="panel">
	<div class="panel_con">
		<div class="security">
			<div class="setup_title clear">
				<div class="setup_title_left">
					<h4>权限设置</h4>
				</div>
				<div class="setup_title_right">
					一共<em>123</em>条数据
				</div>
			</div>
			<div class="setup_operation clear">

				<div class="join_left">
					<input hidden type="text" id="rid" value="${roleByid.rid}">
					<input type="text" hidden id="fids" value="${roleByid.fids}">
					<p>
						<span class="control_span">角色名：</span>
						${roleByid.name}
					</p>
					<p>
						<span class="control_span">描述：</span>
						${roleByid.description}
					</p>


				</div>
				<div class="join_ipt">
					<input id="addFunction" type="button" class="btn_ipt" value="添加权限" />
				</div>
			</div>

		</div>

		<div class="setup_con">
			<table>
				<thead>
				<tr>
					<th><input id="checkall" type="checkbox" value="all">全选</th>
					<th>权限名</th>
					<th>权限路径</th>
					<th>pid</th>
					<th>描述</th>

				</tr>
				</thead>
				<tbody class="tbody_con">
				<!--<tr>
					<td>1</td>
					<td>1</td>
					<td>1</td>
					<td>1</td>

				</tr>-->
				</tbody>
			</table>
		</div>
	</div>
</div>



<div class="apply_reply">
	<div class="reply_top">
		<a role="button" class="apply_btn">
			<span class="glyphicon glyphicon-remove"></span>
		</a>
	</div>
	<div class="reply_ipt">
		<div class="reply_left clear">
			<div class="left">留言者昵称：<span class="user_name">123</span></div>
			<div class="left">留言者id：<span class="user_id">123</span></div>
			<div class="left">留言者邮箱：<span class="user_email">123</span></div>
			<div class="left">留言者时间：<span class="user_time">123</span></div>
		</div>
		<!-- 显示留言内容 -->
		<div class="apply_con">
			asd
		</div>
		<div class="reply_text">
			<div id="editor"></div>
		</div>
		<div class="reply_btn">
			<a role="button" class="btn_a">回复</a>
		</div>
	</div>
</div>

<!--<script type="text/javascript" src="/admin/js/apply.js" ></script>-->
<script type="text/javascript" src="/admin/common/js/wangEditor.min.js" ></script>
<script type="text/javascript">

    $(document).ready(function () {
        initUserRole();
    });
    function initUserRole() {
        $.ajax({
            type: 'get',
            url: '/api/function',
            dataType: "json",
            data: {
                "pageSize": 20,
                "pageNumber": 0
            },
            success: function (result) {
                var data = result.data;
                $(".tbody_con").html("")
                var val = "";
                var fids = $("#fids").val();
                data.forEach(function (value, index) {
                    var fid = value.fid
					if(fids.indexOf(fid) != -1 ) {
//                        alert("包含")
                        val = val + "<tr>" +
                            "<td><input name='rolecheck' checked type='checkbox' value='"+value.fid+"'></td>" +
                            "<td>" + value.name + "</td>" +
                            "<td>" + value.url + "</td>" +
                            "<td>" + value.pid + "</td>" +
                            "<td>" + value.description + "</td>" +
                            "</tr>";

					}else {
                        val = val + "<tr>" +
                            "<td><input name='rolecheck' type='checkbox' value='"+value.fid+"'></td>" +
                            "<td>" + value.name + "</td>" +
                            "<td>" + value.url + "</td>" +
                            "<td>" + value.pid + "</td>" +
                            "<td>" + value.description + "</td>" +
                            "</tr>";
					}

                });
                $(".tbody_con").append(val)
            },
            error: function () {
                layer.msg("系统错误！", {icon: 5});
            }
        });
    }

    //全选,全不选
    $("#checkall").click(function(){
        if (this.checked) {
            $("input[name='rolecheck']").prop("checked", true);
        }else{
            $("input[name='rolecheck']").prop("checked", false);
        }
    });

    $("#addFunction").click(function () {

        var fids = new Array();
        $.each($('input:checkbox:checked'),function(){
            if ($(this).val()=="all") {

			}
            fids.push($(this).val())
        });
        fids.join(',');
        alert(fids);

        $.ajax({
            type: 'get',
            url: '/api/addrolefunction',
            dataType:"json",
            data: {
                'rid': $("#rid").val(),
                'fids': fids.toString()
            },
            success: function (result) {
                if (result.code==200){
                    layer.msg(result.message,{icon: 1})
                    window.setTimeout(function () {
                        window.location.href="/admin/role"
                    },1000)
                } else {
                    layer.msg(result.message,{icon: 5})
                }
            },
            error:function () {
                layer.msg("系统错误！",{icon: 5});
            }
        });
    })




</script>
</body>
</html>
